#include <cstdio>
#include <windows.h>
#include <tlhelp32.h>

DWORD processId;
wchar_t* Convert(const char *orig1)
{
	// Convert to a wchar_t*
	size_t origsize = strlen(orig1) + 1;
	const size_t newsize = 100;
	size_t convertedChars = 0;
	wchar_t* wcstring = (wchar_t *)malloc(origsize);
	mbstowcs_s(&convertedChars, wcstring, origsize, orig1, _TRUNCATE);
	return wcstring;
}

char * Convert2(wchar_t *WStr)
{
	size_t len = wcslen(WStr) + 1;
	size_t converted = 0;
	char *CStr;
	CStr=(char*)malloc(len*sizeof(char));
	wcstombs_s(&converted, CStr, len, WStr, _TRUNCATE);
	return CStr;
}

BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lparam)
{
	//if(!hwnd) return false;
	DWORD id=GetWindowThreadProcessId(hwnd,&id);
	printf("process id: %d %d\n", id, processId);
	if(id==processId)
	{
		printf("THEY MATCH!process id: %d\n", id);
		char buffer[256];
		GetWindowText(hwnd,(LPWSTR)buffer,255);
		printf("%s ", buffer);
	}
	return true;

}

int main( int, char *[] )
{
	//PROCESSENTRY32 entry;
	//entry.dwSize = sizeof(PROCESSENTRY32);

	//HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);

	//if (Process32First(snapshot, &entry) == TRUE)
	//{
	//	while (Process32Next(snapshot, &entry) == TRUE)
	//	{
	//		if (stricmp(Convert2(entry.szExeFile), "cmd.exe") == 0)
	//		{  
	//			HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID);

	//			// Do stuff..
	//			processId = entry.th32ProcessID;
	//			EnumWindows(&EnumWindowsProc,NULL);

	//			//SetLayeredWindowAttributes(hProcess, 0, 0, LWA_ALPHA);

	//			CloseHandle(hProcess);
	//		}
	//	}
	//}

	//CloseHandle(snapshot);

	HWND wnd = FindWindow(0,L"C:\\WINDOWS\\system32\\cmd.exe");
	LONG ExtendedStyle = GetWindowLong( wnd,
		GWL_EXSTYLE );

	SetWindowLong( wnd,
		GWL_EXSTYLE,
		ExtendedStyle | WS_EX_LAYERED );
	SetLayeredWindowAttributes(wnd, 0, 100, LWA_ALPHA);
	return 0;
}
